<template>
  <div class="page">
    <el-radio-group v-model="state.valueType" @change="radioChange">
      <el-radio v-for="(item, index) in state.typeData" :label="item.value" :key="index">{{
        item.label
      }}</el-radio>
    </el-radio-group>
    <el-card :border="false">
      <ProForm ref="proFormRef" :options="formOption" :type="state.valueType"></ProForm>
      <div class="footer">
        <el-button @click="reset">重置</el-button>
        <el-button type="primary" @click="conform">确定</el-button>
      </div>
    </el-card>
    <div>
      <p>结果</p>
      <div>{{ state.result }}</div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref, shallowRef } from 'vue'
import ProForm from '_c/proForm/index.vue'
import customComp from './customComp.vue'
import customComp2 from './customComp2.vue'
const proFormRef = ref(null)
const state = reactive({
  valueType: 'add',
  typeData: [
    {
      label: '新增',
      value: 'add',
    },
    {
      label: '编辑',
      value: 'edit',
    },
    {
      label: '查看',
      value: 'show',
    },
  ],
  result: {}
})
const radioChange = (e) => {
  if (e == 'edit') {
    proFormRef.value.setValue({
      name: '名称',
      name2: '名称',
      cuscompValue: [1, 100],
      customComp2: {},
      attach: [
        {
          "attachId": "54bcb08d59114dc5a6bd644a41ce351c",
          "attachName": "loginLog.jpg",
          "attachSize": 2183071,
          "attachUrl": "http://10.0.240.32/down/chitian/20230727/loginLog.jpg"
        }
      ]
    })
  }
  if (e == 'show') {
    proFormRef.value.setValue({
      name: '查看名称',
      property: 'yes',
      attach: [
        {
          "attachId": "54bcb08d59114dc5a6bd644a41ce351c",
          "attachName": "loginLog.jpg",
          "attachSize": 2183071,
          "attachUrl": "http://10.0.240.32/down/chitian/20230727/loginLog.jpg"
        }
      ]

    },)
  }
}
// 重置
const reset = () => {
  proFormRef.value.clear()
}
// 确定
const conform = () => {
  proFormRef.value.validateForm().then((data) => {
    state.result = data
  })
}
const formOption = reactive({
  form: {
    inline: true,
    labelPosition: 'right',
    labelWidth: '150px',
    size: 'default',
    labelSuffix: '',
  },
  columns: [
    {
      formItem: {
        label: '任务名称',
        required: true,
        prop: 'name',
      },
      attrs: {
        typeName: 'el-input',
        placeholder: '请输入',
      },
      event: {
        change: (val) => {
          console.log(val)
        }
      },
    },
    {
      formItem: {
        label: 'cyselect',
        required: true,
        prop: 'cyselect',
      },
      attrs: {
        typeName: 'CySelect',
        placeholder: '请输入',
        data: [
          { label: '是', value: 'yes' },
          { label: '否', value: 'no' },
        ],
      },
      event: {

      },
    },
    {
      formItem: {
        label: '任务属性',
        prop: 'property',
      },
      attrs: {
        typeName: 'CyRadioGroup',
        data: [
          { label: '是', value: 'yes' },
          { label: '否', value: 'no' },
        ],
      },
    },
    {
      formItem: {
        label: '负责部门',
        prop: 'organId',
      },
      attrs: {
        typeName: 'el-tree-select',
        'check-strictly': true,
        multiple: false,
        clearable: true,
        placeholder: '请选择',
        props: {
          label: 'label',
          value: 'value',
          children: 'subList',
          isLeaf: 'isLeaf',
        },
        filterable: true,
        data: [
          {
            label: '是',
            value: 'yes',
            subList: [
              {
                label: 'chiildren是',
                value: 'chiildrenyes',
              },
            ],
          },
          { label: '否', value: 'no' },
        ],
      },
    },
    {
      formItem: {
        label: '完成日期',
        prop: 'endTime',
      },
      attrs: {
        typeName: 'el-date-picker',
        placeholder: '请选择 ',
        type: 'date',
        format: 'YYYY-MM-DD',
        'value-format': 'YYYY-MM-DD',
        clearable: true,
        disabled: false,
      },
    },
    {
      formItem: {
        label: '月份多选',
        prop: 'selectMonths',
      },
      attrs: {
        typeName: 'cy-select-months',

      },
    },
    {
      formItem: {
        label: '简介',
        prop: 'intro',
        class: 'width100',
      },
      attrs: {
        typeName: 'el-input',
        type: 'textarea',
        'show-word-limit': true,
        maxlength: '512',
      },
    },

    {
      formItem: {
        label: '附件',
        prop: 'attach',
        class: 'width100',
      },
      attrs: {
        action: '/rl-baisha/sxyd/attach/upload',
        typeName: 'cy-upload-file',
      },
    },

    {
      formItem: {
        label: '上传图片',
        prop: 'attach',
        class: 'width100',
      },
      attrs: {
        action: '/rl-baisha/sxyd/attach/upload',
        typeName: 'cy-upload-image',
      },
    },
    {
      formItem: {
        label: '穿梭框',
        prop: 'transfer',
        class: 'width100',
      },
      attrs: {
        typeName: 'cy-transfer',
      
        data: [
          {
            label: 'text',
            key: '1',
          },
        ],
      },
    },
    {
      formItem: {
        label: '自定义组件',
        prop: 'cuscompValue',
        class: 'width100',
        customComponent: true
      },
      attrs: {
        typeName: shallowRef(customComp),
      },
    },
    {
      formItem: {
        label: '自定义组件2',
        prop: 'cuscompValue2',
        class: 'width100',
        customComponent: true
      },
      attrs: {
        typeName: shallowRef(customComp2),
      },
    },
  ],
})
</script>

<style scoped>
.page {
  height: 100%;
  width: 100%;
}

.footer {
  text-align: center;
}
</style>
